<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="stylesheet" type="text/css" href="${ctx}/static/plug/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/static/plug/Hui-iconfont/1.0.8/iconfont.min.css" />
<style type="text/css">
.row {
	margin-top: 15px
}
</style>
<title>景区详情</title>
</head>
<body>
	<div class="panel panel-default">
		<div class="panel-body">
			<form id="dataForm">
				<div class="row cl">
					<label class="form-label col-xs-2"><span class="c-red">*</span>景区名称：</label>
					<div class="form-label col-xs-4">
						<input class="input-text required" type="text" value="${detail.name}" id="name" name="name"></input>
					</div>
					<label class="form-label col-xs-2">景区位置：</label>
					<div class="formControls col-xs-4">
						<input class="input-text" type="text" value="${detail.area}" id="area" name="area"></input>
					</div>
				</div>
				
				<div class="row cl">
					<label class="form-label col-xs-2"><span class="c-red">*</span>公众号appId：</label>
					<div class="form-label col-xs-4">
						<input class="input-text required" type="text" value="${detail.appId}" id="appId" name="appId"></input>
					</div>
					<label class="form-label col-xs-2"><span class="c-red">*</span>公众号accountId：</label>
					<div class="formControls col-xs-4">
						<input class="input-text required" type="text" value="${detail.accountId}" id="accountId" name="accountId"></input>
					</div>
				</div>
				
				<div class="row cl">
					<label class="form-label col-xs-2"><span class="c-red">*</span>支付公众号appId：</label>
					<div class="form-label col-xs-4">
						<input class="input-text required" type="text" value="${detail.payAppId}" id="payAppId" name="payAppId"></input>
					</div>
					<label class="form-label col-xs-2"><span class="c-red">*</span>支付公众号accountId：</label>
					<div class="formControls col-xs-4">
						<input class="input-text required" type="text" value="${detail.payAccountId}" id="payAccountId" name="payAccountId"></input>
					</div>
				</div>
				
				<div class="row cl">
					<label class="form-label col-xs-2"><span class="c-red">*</span>支付公众号SecretKey：</label>
					<div class="form-label col-xs-4">
						<input class="input-text required" type="text" value="${detail.paySecretKey}" id="paySecretKey" name="paySecretKey"></input>
					</div>
					<label class="form-label col-xs-2"><span class="c-red">*</span>支付公众号商户号：</label>
					<div class="formControls col-xs-4">
						<input class="input-text required" type="text" value="${detail.payMchId}" id="payMchId" name="payMchId"></input>
					</div>
				</div>
			</form>
			
			<div class="row cl">
				<label class="form-label col-xs-2"><span class="c-red">*</span>支付公众号支付证书：</label>
				<div class="formControls col-xs-3" style="display: flex">
					<div class="required" id="payCertPath" src="${detail.payCertPath}">${fn:length(detail.payCertPath) > 0 ? '已上传'  : '未上传' }</div>
					<form id="imgForm" method="post" enctype="multipart/form-data">
						<input type="hidden" id="id" name="scenicSpotId" value="${detail.id}" /> 
							<a href="javascript:void();" class="btn btn-primary upload-btn">
							 	<i class="Hui-iconfont">&#xe642;</i>修改
							</a>
						 <input type="file" multiple name="imgFile" class="input-file required" id="file1" accept="application/x-pkcs12"/>
					</form>
				</div>
			</div>
			<div class="row cl" style="text-align: center">
				<button id="updateBtn" class="btn btn-secondary radius size-L" type="button">确定</button>
				<button id="cancelBtn" class="btn btn-secondary radius size-L" type="button">取消</button>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		var canSubmit = true;
		$(function() {
			$("#updateBtn").click(function() {
				if(!$("#dataForm").valid()) {
					return;
				}
				
				if(!$("#payCertPath").attr("src")) {
					if(!$("#imgForm").valid()) {
						return;
					}
				}
				
				if(canSubmit) {
					canSubmit = false;
					var updateData = new Object();
					updateData.name = $("#name").val();
					updateData.area = $("#area").val();
					updateData.appId = $("#appId").val();
					updateData.accountId = $("#accountId").val();
					updateData.payAppId = $("#payAppId").val();
					updateData.payAccountId = $("#payAccountId").val();
					updateData.paySecretKey = $("#paySecretKey").val();
					updateData.payMchId = $("#payMchId").val();
					updateData.payCertPath = $("#payCertPath").attr("src");
					updateData.id = $("#id").val();
					var tips = "";
					if(updateData.id) {
						tips = "更新";
					} else {
						tips = "新增";
					}
					$.post("${ctx}/scenicSpot/saveOrUpdate", updateData, function(data) {
						canSubmit = true;
						if (data.result) {
							layer.confirm(tips + '成功!', {
								btn : [ '确定' ]
							}, function() {
								var index = parent.layer.getFrameIndex(window.name);
								parent.reloadData();
								parent.layer.close(index);
							});
						} else {
							layer.confirm(tips + "失败!" + data.errorMsg, {
								btn : [ '确定' ]
							}, function() {
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							});
						}
					});
				}
			});

			$("#cancelBtn").click(function() {
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index);
			});
			
			$("#file1").change(function() {
				$("#imgForm").attr("action","${ctx}/file/upload");
				$("#imgForm").attr("target","blankFrame");
				$("#imgForm").submit();
			});
			
		});
		
		function refreshUpload(img) {
			$("#payCertPath").html("上传成功");
			$("#payCertPath").attr("src",img);
		}
	</script>
	<iframe id="blankFrame" name="blankFrame" style="display: none"> </iframe>
</body>
</html>
